package com.atguigu.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class PaymentService {

    public String paymentInfo_OK(Integer id){
        return "线程池："+Thread.currentThread().getName()+"paymentInfo_OK,id:"+id+"hahahahhaha";
    }


    @HystrixCommand(fallbackMethod = "paymentInfo_Time_out_Handler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String paymentInfo_Time_out(Integer id){

        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "线程池："+Thread.currentThread().getName()+"paymentInfo_Time_out,id:"+id+"5555555555";
    }

    public String paymentInfo_Time_out_Handler(Integer id){
        return "线程池："+Thread.currentThread().getName()+"paymentInfo_Time_out,id:"+id+"!!!处理!!!";

    }

}
